﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam2.Biz;
using MockPrjTeam2.Entity;
namespace MockPrjTeam2.Pages.ControlOrg
{
    public partial class SupportingMeterialListFrame : System.Web.UI.UserControl
    {
        public int orgId;
        private SupportingMeterialBiz supportingMeterial;
       // public int OrganizationId { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request.Params["id"], out orgId))
            {
                Response.Redirect("../Forms/AddSupportingMaterial.aspx");
            }
            else
            {
                supportingMeterial = new SupportingMeterialBiz();
            }
            if (!IsPostBack)
            {
                this.LoadSupportingMeterialByOrgId();
            }
        }
        private void LoadSupportingMeterialByOrgId()
        {
            SupportingMeterial supporting = supportingMeterial.GetSupportingMaterialById1(orgId);
            Session["userId"] = supporting.UserID;
            GridViewSupportingMaterials.DataSource = supportingMeterial.GetSupportingMaterialById(orgId);
            GridViewSupportingMaterials.DataBind();

        }
        protected void CbxInactive_CheckedChanged(object sender, EventArgs e)
        {
            if(CbxInactive.Checked)
            {
                GridViewSupportingMaterials.DataSource = supportingMeterial.GetSupportingMaterialInActive(orgId);
                GridViewSupportingMaterials.DataBind();
            }
            else if(CbxInactive.Checked==false)
            {
                GridViewSupportingMaterials.DataSource = supportingMeterial.GetSupportingMaterialById(orgId);
                GridViewSupportingMaterials.DataBind();
            }
        }

        protected void LinkButtonCreate_Command(object sender, CommandEventArgs e)
        {
            Response.Redirect(string.Format(CultureInfo.CurrentCulture,
                                           "../Forms/AddSupportingMaterial.aspx?organisationId={0}",orgId));
        }
    
        protected void GridViewSupportingMaterials_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridViewSupportingMaterials.PageIndex = e.NewPageIndex;
            if (CbxInactive.Checked)
            {
                GridViewSupportingMaterials.DataSource = supportingMeterial.GetSupportingMaterialInActive(orgId);
                GridViewSupportingMaterials.DataBind();
            }
            else if (CbxInactive.Checked == false)
            {
                GridViewSupportingMaterials.DataSource = supportingMeterial.GetSupportingMaterialById(orgId);
                GridViewSupportingMaterials.DataBind();
            }
            else
            {
                this.LoadSupportingMeterialByOrgId();
            }
        }

        protected void LinkButtonUrl_Command(object sender, CommandEventArgs e)
        {
            if (e.CommandArgument.Equals("False"))
            {
                int organisationId = int.Parse(e.CommandName, CultureInfo.CurrentCulture);
                bool result = supportingMeterial.SetActiveSupportingMateria(organisationId, true);
            }


            Response.Redirect(string.Format(CultureInfo.CurrentCulture, "../Forms/SupportingMaterialDetails.aspx?id={0}", e.CommandName));
        }
       

        

        
    }
}